package com.weixing.mall.provider.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weixing.mall.provider.mapper.HelpDocMapper;
import com.weixing.mall.provider.model.domain.HelpDoc;
import com.weixing.mall.provider.model.dto.cms.HelpDocDto;
import com.weixing.mall.provider.model.query.HelpDocQuery;
import com.weixing.mall.provider.model.vo.cms.HelpDocEditVo;
import com.weixing.mall.provider.model.vo.cms.HelpDocVo;
import com.weixing.mall.provider.service.IHelpDocService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @ClassName HelpDocServiceImpl
 * @Description TODO <br/>
 * @Author gjq
 * @Modified By:
 * @Date 2019/7/26
 * @Version 1.0
 **/
/**
 * <p>
 * 帮助文档 服务实现类
 * </p>
 *
 * @author Small
 * @since 2019-11-18
 */
@Service
public class HelpDocServiceImpl extends ServiceImpl<HelpDocMapper, HelpDoc> implements IHelpDocService {

    @Override
    public IPage<HelpDocVo> selectOfPage(Page page, HelpDocQuery helpDocQuery) {
        return baseMapper.selectListOfPage(page,helpDocQuery);
    }

    @Override
    public void save(HelpDocDto helpDocDto,Long uid) {
        HelpDoc helpDoc = new HelpDoc();
        BeanUtils.copyProperties(helpDocDto,helpDoc);
        if (null == helpDocDto.getId()){
            helpDoc.setCreatedBy(uid);
            helpDoc.setCreatedTime(new Date());
            save(helpDoc);
        }else{
            helpDoc.setUpdatedTime(new Date());
            helpDoc.setUpdatedBy(uid);
            updateById(helpDoc);
        }
    }

    @Override
    public HelpDocEditVo selectHelpDocVoById(Long id) {
        return baseMapper.selectHelpDocVoById(id);
    }
}
